<?php
class Message {
    var $msg = 'Hello World';
    function setMsg ($msg) {
        $this->msg=$msg;
    }
    function getMsg () {
        return $this->msg;
    }
}
 
class MessageFactory {
    // Return a reference to an instance of Message
    function & createMessage () {
        $ret = & new Message
        return  $ret;
    }
}
 
$factory= new MessageFactory;
$msg=$factory->createMessage();
echo ($msg->getMsg());
?>
